package cn.tedu.basic;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class PracticeJdbc3 {
    public static void main(String[] args) {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            con = JdbcUtils3.getConnection();
            //setString会将传入的所有数据当字符串看待,并且遇到转义符,会自动忽略转义符;
            String sql = "select * from user where name=? and pwd=?";
            ps = con.prepareStatement(sql);
            ps.setString(1, "jack");
            ps.setString(2, "123");

            rs = ps.executeQuery();

            while (rs.next()) {
                for (int i = 1; i < 3; i++) {
                    System.out.println(rs.getString(i));
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils3.close(con, ps, rs);
        }
    }
}
